﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Stockholm.SOA.Kaskelot.WCF.DataContracts;
using Kaskelot.SP.Services;

namespace Kaskelot.SP.UI.CONTROLTEMPLATES.Kaskelot.SP.UI.FormControls
{
    public partial class Flerval : FormControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (BlankettService svc = new BlankettService())
            {
                if (FaltData != null)
                {
                    FaltAlternativ[] alternativ = svc.GetFaltAlternativForFalt(FaltData.Falt.Id).OrderBy(fa => fa.Namn).ToArray();
                    rpChoices.DataSource = alternativ;
                    rpChoices.DataBind();
                }
            }
        }

        protected string Checked(object obj)
        {
            string result = "";

            FaltAlternativ item = obj as FaltAlternativ;

            if (FaltData.Data != null)
            {
                string faltData = "|" + FaltData.Data + "|";
                if (faltData.ToLower().Contains("|" + item.Namn.ToLower() + "|"))
                    result = "checked=\"checked\"";
            }

            return result;
        }
    }
}